/**
  * AntDroid Copyright (c) 2008-2012 INRIA, University of Lille 1
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * 
  * Contact: nicolas.haderer@inria.fr
  *
  * Author: Haderer Nicolas
  */
package com.google.antranking.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;


public class AtConfiguration {

	public static SharedPreferences getAtConfiguration(Context mContext){
		return PreferenceManager.getDefaultSharedPreferences(mContext);
	}
	
	public static Editor getEditorConfiguration(Context mContext){
		return AtConfiguration.getAtConfiguration(mContext).edit();
	}
	
	public static String getStringValue(Context mContext, String key, String defaultValue){
		return AtConfiguration.getAtConfiguration(mContext).getString(key, defaultValue);
	}
	public static Integer getIntValue(Context mContext, String key, Integer defaultValue){
		return AtConfiguration.getAtConfiguration(mContext).getInt(key, defaultValue);
	}
	public static Float getDoubleValue(Context mContext, String key, Float defaultValue){
		return AtConfiguration.getAtConfiguration(mContext).getFloat(key, defaultValue);
	}
	public static Long getLongValue(Context mContext, String key, Long defaultValue){
		return AtConfiguration.getAtConfiguration(mContext).getLong(key, defaultValue);
	}
	public static Boolean getBooleanValue(Context mContext, String key, Boolean defaultValue){
		return AtConfiguration.getAtConfiguration(mContext).getBoolean(key, defaultValue);
	}
	
	
	public static void initializeConfigurationFile(Context mContext){
		
		final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(mContext);
		final Editor editor = shared.edit();
		
		if (!shared.contains(AtConstant.PREF_HOST)){
			editor.putString(AtConstant.PREF_HOST, "http://antdroid.jelastic.com");
		}
		if (!shared.contains(AtConstant.PREF_USERNAME)){
			editor.putString(AtConstant.PREF_USERNAME, "username");
		}
		if (!shared.contains(AtConstant.PREF_PASSWORD)){
			editor.putString(AtConstant.PREF_PASSWORD, "password");
		}
		if (!shared.contains(AtConstant.PREF_NOTIFICATION_ALERT)){
			editor.putBoolean(AtConstant.PREF_NOTIFICATION_ALERT,false);
		}
		if (!shared.contains(AtConstant.PREF_NOTIFICATION_INFO)){
			editor.putBoolean(AtConstant.PREF_NOTIFICATION_INFO,true);
		}
		
		
		
		editor.commit();
	}
	
}
